<template>
  <el-dialog
    :title="!dataForm.groupid ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="110px">
    <el-form-item label="用户组名" prop="name">
      <el-input v-model="dataForm.name" placeholder="用户组名"></el-input>
    </el-form-item>
    <el-form-item label="系统组" prop="issystem">
      <el-input v-model="dataForm.issystem" placeholder="系统组"></el-input>
    </el-form-item>
    <el-form-item label="积分小于" prop="point">
      <el-input v-model="dataForm.point" placeholder="积分小于"></el-input>
    </el-form-item>
    <el-form-item label="允许上传附件" prop="allowvisit">
      <el-input v-model="dataForm.allowvisit" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="投稿权限" prop="allowpost">
      <el-input v-model="dataForm.allowpost" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="投稿不需审核" prop="allowpostverify">
      <el-input v-model="dataForm.allowpostverify" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="搜索权限" prop="allowsearch">
      <el-input v-model="dataForm.allowsearch" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="自助升级" prop="allowupgrade">
      <el-input v-model="dataForm.allowupgrade" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="发短消息" prop="allowsendmessage">
      <el-input v-model="dataForm.allowsendmessage" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="星星数" prop="sort">
      <el-input v-model="dataForm.sort" placeholder="星星数"></el-input>
    </el-form-item>
    <el-form-item label="积分扣减金额" prop="jifendikou">
      <el-input v-model="dataForm.jifendikou" placeholder="积分扣减金额"></el-input>
    </el-form-item>
    <el-form-item label="运费折扣" prop="discount">
      <el-input v-model="dataForm.discount" placeholder="运费折扣"></el-input>
    </el-form-item>
    <el-form-item label="优惠券" prop="yhq">
      <el-input v-model="dataForm.yhq" placeholder="优惠券"></el-input>
    </el-form-item>
    <el-form-item label="精细拍照" prop="finePhoto">
      <el-input v-model="dataForm.finePhoto" placeholder="精细拍照"></el-input>
    </el-form-item>
    <el-form-item label="免费仓储天数" prop="freeStorage">
      <el-input v-model="dataForm.freeStorage" placeholder="免费仓储天数"></el-input>
    </el-form-item>
    <el-form-item label="国内退换货服务" prop="exchangePurchase">
      <el-input v-model="dataForm.exchangePurchase" placeholder="国内退换货服务"></el-input>
    </el-form-item>
    <el-form-item label="佣金比例" prop="brokeragePerCentum">
      <el-input v-model="dataForm.brokeragePerCentum" placeholder="佣金比例"></el-input>
    </el-form-item>
    <el-form-item label="积分文字说明" prop="pointText">
      <el-input v-model="dataForm.pointText" placeholder="积分文字说明"></el-input>
    </el-form-item>
    <el-form-item label="折扣文字说明" prop="discountText">
      <el-input v-model="dataForm.discountText" placeholder="折扣文字说明"></el-input>
    </el-form-item>
    <el-form-item label="优惠券文字说明" prop="yhqText">
      <el-input v-model="dataForm.yhqText" placeholder="优惠券文字说明"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          groupid: 0,
          moneyText: '',
          name: '',
          issystem: '',
          starnum: '',
          point: '',
          allowmessage: '',
          allowvisit: '',
          allowpost: '',
          allowpostverify: '',
          allowsearch: '',
          allowupgrade: '',
          allowsendmessage: '',
          allowpostnum: '',
          allowattachment: '',
          priceY: '',
          priceM: '',
          priceD: '',
          icon: '',
          usernamecolor: '',
          description: '',
          sort: '',
          disabled: '',
          jifendikou: '',
          discount: '',
          yhq: '',
          finePhoto: '',
          freeStorage: '',
          exchangePurchase: '',
          brokeragePerCentum: '',
          money: '',
          pointText: '',
          discountText: '',
          yhqText: ''
        },
        dataRule: {
          name: [
            { required: true, message: '用户组名不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.groupid = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.groupid) {
            this.$http({
              url: this.$http.adornUrl(`/member_group/v9membergroup/info/${this.dataForm.groupid}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.moneyText = data.v9MemberGroup.moneyText
                this.dataForm.name = data.v9MemberGroup.name
                this.dataForm.issystem = data.v9MemberGroup.issystem
                this.dataForm.starnum = data.v9MemberGroup.starnum
                this.dataForm.point = data.v9MemberGroup.point
                this.dataForm.allowmessage = data.v9MemberGroup.allowmessage
                this.dataForm.allowvisit = data.v9MemberGroup.allowvisit
                this.dataForm.allowpost = data.v9MemberGroup.allowpost
                this.dataForm.allowpostverify = data.v9MemberGroup.allowpostverify
                this.dataForm.allowsearch = data.v9MemberGroup.allowsearch
                this.dataForm.allowupgrade = data.v9MemberGroup.allowupgrade
                this.dataForm.allowsendmessage = data.v9MemberGroup.allowsendmessage
                this.dataForm.allowpostnum = data.v9MemberGroup.allowpostnum
                this.dataForm.allowattachment = data.v9MemberGroup.allowattachment
                this.dataForm.priceY = data.v9MemberGroup.priceY
                this.dataForm.priceM = data.v9MemberGroup.priceM
                this.dataForm.priceD = data.v9MemberGroup.priceD
                this.dataForm.icon = data.v9MemberGroup.icon
                this.dataForm.usernamecolor = data.v9MemberGroup.usernamecolor
                this.dataForm.description = data.v9MemberGroup.description
                this.dataForm.sort = data.v9MemberGroup.sort
                this.dataForm.disabled = data.v9MemberGroup.disabled
                this.dataForm.jifendikou = data.v9MemberGroup.jifendikou
                this.dataForm.discount = data.v9MemberGroup.discount
                this.dataForm.yhq = data.v9MemberGroup.yhq
                this.dataForm.finePhoto = data.v9MemberGroup.finePhoto
                this.dataForm.freeStorage = data.v9MemberGroup.freeStorage
                this.dataForm.exchangePurchase = data.v9MemberGroup.exchangePurchase
                this.dataForm.brokeragePerCentum = data.v9MemberGroup.brokeragePerCentum
                this.dataForm.money = data.v9MemberGroup.money
                this.dataForm.pointText = data.v9MemberGroup.pointText
                this.dataForm.discountText = data.v9MemberGroup.discountText
                this.dataForm.yhqText = data.v9MemberGroup.yhqText
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/member_group/v9membergroup/${!this.dataForm.groupid ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'groupid': this.dataForm.groupid || undefined,
                'moneyText': this.dataForm.moneyText,
                'name': this.dataForm.name,
                'issystem': this.dataForm.issystem,
                'starnum': this.dataForm.starnum,
                'point': this.dataForm.point,
                'allowmessage': this.dataForm.allowmessage,
                'allowvisit': this.dataForm.allowvisit,
                'allowpost': this.dataForm.allowpost,
                'allowpostverify': this.dataForm.allowpostverify,
                'allowsearch': this.dataForm.allowsearch,
                'allowupgrade': this.dataForm.allowupgrade,
                'allowsendmessage': this.dataForm.allowsendmessage,
                'allowpostnum': this.dataForm.allowpostnum,
                'allowattachment': this.dataForm.allowattachment,
                'priceY': this.dataForm.priceY,
                'priceM': this.dataForm.priceM,
                'priceD': this.dataForm.priceD,
                'icon': this.dataForm.icon,
                'usernamecolor': this.dataForm.usernamecolor,
                'description': this.dataForm.description,
                'sort': this.dataForm.sort,
                'disabled': this.dataForm.disabled,
                'jifendikou': this.dataForm.jifendikou,
                'discount': this.dataForm.discount,
                'yhq': this.dataForm.yhq,
                'finePhoto': this.dataForm.finePhoto,
                'freeStorage': this.dataForm.freeStorage,
                'exchangePurchase': this.dataForm.exchangePurchase,
                'brokeragePerCentum': this.dataForm.brokeragePerCentum,
                'money': this.dataForm.money,
                'pointText': this.dataForm.pointText,
                'discountText': this.dataForm.discountText,
                'yhqText': this.dataForm.yhqText
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
 
